class mouse_click_row_event :
    def __init__ ( self , mediator , row ) :
        self . _mediator = mediator
        self . _row = row
    def on_click ( self ) :
        self . _mediator . on_table_row_click ( self . _row )

class table_gui :
    def __init__ ( self , mediator ) :
        self . _mediator = mediator
        self . _created_label = None
        self . _created_entry = None
        self . _mouse_button_1_event_replied = None
    def gui_create_label_reply ( self , label ) :
        self . _created_label = label
    def gui_create_entry_reply ( self , entry ) :
        self . _created_entry = entry
    def gui_mouse_button_1_event_reply ( self , handler ) :
        self . _mouse_button_1_event_replied = handler
    def create_new_table_in_frame ( self , table_frame ) :
        self . _table_frame = table_frame
        self . _col = 0
        self . _row = 0
        self . _widgets_in_a_row = { }
        self . _widget_click_events = [ ]
        self . _mouse_button_1_event_replied = None
    def finish_table_row ( self ) :
        self . _col = 0
        self . _row += 1
    def add_table_label ( self , text , anchor , borderwidth ) :
        self . _mediator . gui_create_label_request \
                ( master = self . _table_frame
                , text = '' if text == None else text
                , borderwidth = 1 if borderwidth == None else borderwidth
                , relief = self . _mediator . gui_relief_sunken ( )
                , anchor = anchor
                )
        widget = self . _created_label
        self . _grid_widget ( widget )
        if self . _row not in self . _widgets_in_a_row :
            self . _widgets_in_a_row [ self . _row ] = [ widget ]
        else :
            self . _widgets_in_a_row [ self . _row ] += [ widget ]
        self . _mediator . gui_mouse_button_1_event_request \
            ( widget 
            , mouse_click_row_event ( self . _mediator , self . _row ) . on_click
            )
        self . _widget_click_events += [ self . _mouse_button_1_event_replied ]
    def add_table_entry_request ( self ) :
        self . _mediator . gui_create_entry_request ( master = self . _table_frame , borderwidth = 1 )
        widget = self . _created_entry
        self . _grid_widget ( widget )
        self . _mediator . add_table_entry_reply ( widget )
    def select_table_row ( self , row ) :
        for widget in self . _widgets_in_a_row [ row ] :
            self . _mediator . gui_push_background_color ( widget )
            self . _mediator . gui_set_background_color ( widget , self . _mediator . gui_color_light_blue ( ) )
    def unselect_table_row ( self , row ) :
        for widget in self . _widgets_in_a_row [ row ] :
            self . _mediator . gui_pop_background_color ( widget )
    def bold_table_row ( self , row ) :
        for widget in self . _widgets_in_a_row [ row ] :
            self . _mediator . gui_push_widget_font ( widget )
            self . _mediator . gui_set_widget_font_weight_to_bold ( widget )
    def unbold_table_row ( self , row ) :
        for widget in self . _widgets_in_a_row [ row ] :
            self . _mediator . gui_pop_widget_font ( widget )
    def _grid_widget ( self , widget ) :
        self . _mediator . gui_grid \
            ( widget = widget
            , column = self . _col
            , row = self . _row
            , sticky = self . _mediator . gui_sticky_nesw ( )
            )
        self . _col += 1
